package com.gjy.spring.s11.jdk;

import java.lang.reflect.Method;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-12-20 15:45:00
 */
public class S11Jdk {

    interface Foo {
        void foo();

        int bar();
    }

    static class Target implements Foo {

        @Override
        public void foo() {
            System.out.println("foo");
        }

        @Override
        public int bar() {
            System.out.println("bar");
            return ThreadLocalRandom.current().nextInt(100);
        }
    }

    interface InvocationHandler {
        Object invoke(Object proxy, Method method, Object[] param) throws Throwable;
    }

    public static void main(String[] args) {
        Foo proxy0 = new $Proxy0(new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] param) throws Throwable {
                System.out.println("before");
                return method.invoke(new Target(), param);
            }
        });
        proxy0.foo();
        proxy0.bar();
    }
}
